﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2
{
    

    public class Game
    {
		public const int rowSize = 4;
        public const int fieldSize = rowSize*rowSize;


        public List<FeefteenCell> cells = new List<FeefteenCell>();
        public int emptyPos = fieldSize - 1;
        private GameBoard gameBoard;

        public Game(GameBoard gameBoard)
        {

            this.gameBoard = gameBoard;
                
        }

        public void click(FeefteenCell cell)
        {
            int val = cells.IndexOf(cell);


            if (val == emptyPos)
            {
                // doNothing
                return;
            }
            else if (val == emptyPos - 1 || val == emptyPos + 1 || val == emptyPos + rowSize || val == emptyPos - rowSize)
            {
                FeefteenCell cell1 = cells[val];
                cells[val] = cells[emptyPos];
                cells[emptyPos] = cell1;
                emptyPos = val;
            }

            //gameBoard.clear();
            gameBoard.fillCells();

        }
    }
}
